// aenpc.txt
// Like basicnpc, but can also project a damaging AE. 
// Memory Cells:
//   Cell 0 - If 0, default behavior. If 1, it doesnt fidget.
//   Cell 1,2 - Stuff done flag. If both 0, nothing. Otherwise when this is killed, set to 1.
//   Cell 3 - Type of AE
//		0 - fire, does 1-6 * level
//		1 - cold, does 1-8 * level
//		2 - energy, does 1-10 * level
//		3 - slow
//		4 - debuff
//		5 - daze
//		6 - charm
//		7 - fear
//		8 - acid
//      9 - lightning aura
//		10 - poison
// 		11 - cleave (1-8 dam per level)
//   Cell 4 - Range of AE, Left at default of 4 if 0
//   Cell 5 - Number of state when talked to. Plays default text if 0.
//   Cell 6 - % chance of using AE, defaults to 50% if left at 0

begincreaturescript;

variables;

short i,target;
short last_abil;
short ae_chance = 50;
short ae_range = 3;

body;

beginstate INIT_STATE;
	set_name(ME,"Gusta");
	set_boss_level(ME,2);
	set_new_abil(ME,20);
	
	if (has_spec_item(20) == 0)
		erase_char(ME);
	if (gf(62,15) > 0)
		erase_char(ME);
		
	last_abil = get_current_tick();

	if (get_memory_cell(6) != 0)
		ae_chance = get_memory_cell(6);
	break;

beginstate DEAD_STATE;

break;

beginstate START_STATE; 
	// if I have a target for some reason, go attack it
	if (target_ok()) {
		if (dist_to_char(get_target()) <= 16)
			set_state(3);
			else set_foe_target(ME,-1);
		}
	
	if (get_foe_target(ME,8,0)) {
		do_attack();
		set_state(3);
		}
	if (who_shot_me() >= 0) {
		set_foe_target(ME,who_shot_me());
		do_attack();
		set_state(3);
		}
	if ((gf(62,2) > 0) || (char_ok(8) == FALSE)) {
		if (gf(62,15) > 0) {
			if (dist_to_nav_point(ME,0) <= 2)
				erase_char(ME);
				
			approach_nav_point(ME,0,1);
			}
			else {
				if (get_nearest_party_char(5) >= 0) {
					sf(62,15,1);
					talk_no_exit(90);
					}
				approach_char(ME,pc_num(),1);
				}
		}
		

	if (am_i_doing_action() == FALSE)
		end_combat_turn();
break;

beginstate 3; // attacking
	if (target_ok() == FALSE)
		set_state(START_STATE);

	if ((get_ran(1,0,100) < ae_chance) && (is_combat()) && 
	  (tick_difference(last_abil,get_current_tick()) > 0)) {
		run_char_animation(2,1,35);	
		last_abil = get_current_tick();

			print_named_str(ME,"spins around, cleaving the air with a mighty blow.");
			damage_nearby(get_ran(get_level(ME) + get_attack_bonus(ME),1,8),ae_range,0,0);
			pc_heard_sound_delay(3,100);				
			spray_missiles(15,12,ae_range);

		end();
		}
		
	do_attack();
break;

beginstate TALKING_STATE;
		print_str("Talking: He doesn't respond. He's in a hurry.");

break;